package com.mbyte.easy.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mbyte.easy.admin.entity.Draft;
import com.mbyte.easy.admin.service.IDraftService;
import com.mbyte.easy.common.constant.DraftIsPass;
import com.mbyte.easy.common.constant.DraftType;
import com.mbyte.easy.common.constant.StateDic;
import com.mbyte.easy.common.controller.BaseController;
import com.mbyte.easy.common.web.AjaxResult;
import com.mbyte.easy.util.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassNameBlockLeaderController
 * @Description 版块负责人审核
 * @Author myr
 * @Date 2019/12/10 19:40
 * @Version 1.0
 **/
@Slf4j
@Controller
@RequestMapping("/draft/block")
public class BlockLeaderController extends BaseController {

    private String prefix = "admin/draft/writer/";

    @Autowired
    private IDraftService draftService;

    /**
     * 版块负责人查询下属的稿件列表
     * 待检查列表应该有一个显示
     * @param model
     * @param pageNo
     * @param pageSize
     * @param draft
     * @return
     */
    @RequestMapping
    public String index(Model model,
                        @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,String createTimeSpace,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                        Draft draft) {
//        draft.setStatusCode(StateDic.Block_Leader_Pass);
        IPage<Draft> pageInfo = draftService.blockIndex(pageNo,pageSize,draft,createTimeSpace);
        model.addAttribute("searchInfo", draft);//查询条件前端回显
        model.addAttribute("pageInfo", new PageInfo(pageInfo));//分页数据
        model.addAttribute("draftTypes",draftService.setDraftType());//稿件类型回显
        model.addAttribute("draftCheckStatus",draftService.setDraftCheckStatus());//稿件审核状态回显
        model.addAttribute("stateDic", StateDic.stateDic());
        model.addAttribute("time",createTimeSpace);
        return prefix+"blockLeader-draft";
    }

    /**
     * 版块负责人审核通过
     * @param model
     * @param draftId
     * @return
     */
    @PostMapping("check")
    @ResponseBody
    public AjaxResult check(Model model, String draftId){
        log.info("the draftid is --> {}",draftId);
        return toAjax(draftService.blockLeaderPass(Long.valueOf(draftId)));
    }

    /**
     * 稿件类型数据回显
     * @param model
     */
    public void setDraftType(Model model){
        Map<Integer,String> types = new HashMap<Integer,String>();
        types.put(DraftType.Image_Text,"图文");
        types.put(DraftType.QA,"问答");
        types.put(DraftType.PPT,"PPT");
        types.put(DraftType.Audio,"音频");
        model.addAttribute("draftTypes",types);
    }

    /**
     * 稿件审核状态回显
     * @param model
     */
    public void setDraftCheckStatus(Model model){
        Map<Integer,String> status = new HashMap<Integer,String>();
        status.put(DraftIsPass.Pass,"已通过");
        status.put(DraftIsPass.NotPass,"未通过");
        status.put(DraftIsPass.NotCheck,"未审核");
        model.addAttribute("draftCheckStatus",status);
    }

    /**
     * 七队板块负责人 已通过
     * @param model
     * @param pageNo
     * @param createTimeSpace
     * @param pageSize
     * @param draft
     * @return
     */
    @RequestMapping("videoIndex")
    public String videoIndex(Model model,
                        @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,String createTimeSpace,
                        @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                        Draft draft) {
//        draft.setStatusCode(StateDic.Block_Leader_Pass);
        IPage<Draft> pageInfo = draftService.blockVideoIndex(pageNo,pageSize,draft,createTimeSpace);
        model.addAttribute("searchInfo", draft);//查询条件前端回显
        model.addAttribute("pageInfo", new PageInfo(pageInfo));//分页数据
        model.addAttribute("draftTypes",draftService.setDraftType());//稿件类型回显
        model.addAttribute("draftCheckStatus",draftService.setDraftCheckStatus());//稿件审核状态回显
        model.addAttribute("stateDic", StateDic.stateDic());
        model.addAttribute("time",createTimeSpace);
        return prefix+"blockLeader-video";
    }

}
